package com.msb.springboot_mybatis.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.msb.springboot_mybatis.entity.Account;
import com.msb.springboot_mybatis.mapper.AccountMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author sunpeng
 * @Date 2021-07-12 14:29
 */
@Service
public class AccountService {

    @Autowired
    private AccountMapper accountMapper;

    public List<Account> queryAccount(){
        return accountMapper.queryAccount();
    }

    public List<Account> pageAccount(Integer pageNum, Integer pageSize) {
        Page<Account> pages = PageHelper.startPage(pageNum, pageSize);
        List<Account> accounts = accountMapper.queryAccount();
        PageInfo<Account> pi =new PageInfo<>(accounts);
        System.out.println("当前页"+pi.getPageNum());
        System.out.println("总页数"+pi.getPages());
        System.out.println("页大小"+pi.getSize());
        System.out.println("总记录数"+pi.getTotal());
        System.out.println("当前页数据"+pi.getList());
        return accounts;
    }
}
